from pymysql import connect
import hashlib

USERNAME = 'root'
PASSWORD = 'mysql'
HOST = '127.0.0.1'
PORT = 3306
DATABASE = 'zhengzhou_house_data'


def connect_to_mysql():
    return connect(user=USERNAME, password=PASSWORD, host=HOST, port=PORT, database=DATABASE)


def response_fp(title, price):
    fp = hashlib.sha1()
    fp.update(str(title).encode())
    fp.update(str(price).encode())
    return fp.hexdigest()


def get_set_data():
    set_data = set()

    sql_str = "select title, price from soufang"

    conx = connect_to_mysql()
    cursor = conx.cursor()

    cursor.execute(sql_str)
    conx.commit()
    result = cursor.fetchall()

    for title, price in result:
        fp = response_fp(title, price)
        set_data.add(fp)

    conx.close()
    return set_data


if __name__ == '__main__':
    get_set_data()